package com.concurrent.chapter8.concurrent02;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class Main {
	public static void main(String[] args) {
		List<Runnable> runnables = new ArrayList<>();
		runnables.add(new MyRunnableA());
		runnables.add(new MyRunnableB());
		ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
		System.out.println("x=" + System.currentTimeMillis());
		int delay = 5;
		TimeUnit unit = TimeUnit.SECONDS;
		scheduledExecutorService.schedule(runnables.get(0), delay, unit);
		scheduledExecutorService.schedule(runnables.get(1), delay, unit);
		System.out.println("y=" + System.currentTimeMillis());
	}
}
